package com.hejjon.core.constant;

import com.hejjon.core.bean.SettingNodeBean;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

import static com.hejjon.core.constant.SettingConstants.RecordOperLog.Record;

public class SettingConstants {

    @Getter
    public enum SettingsEnum {

        // 此处扩展新的配置项

        /**
         * 表格添加数据操作模式
         */
        TableDataAddMode("TableDataAddMode", "radioButton",  "row_add", "表格添加数据操作模式,单选框"),

        /**
         * 表格数据删除模式
         */
        TableDataDeleteMode("TableDataDeleteMode", "radioButton", "physics_delete","表格数据删除模式,单选框"),

        /**
         * 是否记录操作日志
         */
        RecordOperLog("RecordOperLog", "switch", Record.getCode(), "记录操作日志"),
        ;


        private final String name;

        private final String uiType;

        private final String defaultValue;

        private final String desc;

        SettingsEnum(String name, String uiType, String defaultValue, String desc) {
            this.name = name;
            this.uiType = uiType;
            this.defaultValue = defaultValue;
            this.desc = desc;
        }

        /**
         * 获取设置项 枚举
         */
        public static SettingsEnum getInstance(String settingName) {
            for (SettingsEnum settingsEnum : SettingsEnum.values()) {
                if (settingsEnum.name().equals(settingName)) {
                    return settingsEnum;
                }
            }
            return null;
        }


//        public static List<SettingNodeBean>  getSettingNodeList(String settingName) {
//            SettingConstants.SettingsEnum settingsEnum = SettingConstants.SettingsEnum.getInstance(settingName);
//            if (settingsEnum == null) {
//                throw new BusinessException("设置项未知！");
//            }
//            List<SettingNodeBean> list = new ArrayList<>();
//            switch (settingsEnum) {
//                case TableDataAddMode:
//                    list = SettingConstants.TableDataAddMode.getSettingNodeList();
//                    break;
//                case TableDataDeleteMode:
//                    list = SettingConstants.TableDataDeleteMode.getSettingNodeList();
//                    break;
//            }
//            return list;
//        }

        /**
         * 获取设置节点
         */
        public List<SettingNodeBean> getSettingNodeList() {
            List<SettingNodeBean> list = new ArrayList<>();
            switch (this) {
                case TableDataAddMode:
                    list = SettingConstants.TableDataAddMode.getSettingNodeList();
                    break;
                case TableDataDeleteMode:
                    list = SettingConstants.TableDataDeleteMode.getSettingNodeList();
                    break;
            }
            return list;
        }


    }



    /**
     * 表格添加数据操作模式
     */
    @Getter
    public enum TableDataAddMode {

        RowAdd("row_add",  "添加行","表格添加行"),

        Dialog("dialog", "弹窗", "页面弹出框");

        private final String code;

        private final String label;

        private final String desc;

        TableDataAddMode(String code, String label, String desc) {
            this.code = code;
            this.label = label;
            this.desc = desc;
        }

        public static List<SettingNodeBean> getSettingNodeList() {
            List<SettingNodeBean> settingNodeList = new ArrayList<>();
            for (TableDataAddMode value : TableDataAddMode.values()) {
                SettingNodeBean snb = new SettingNodeBean();
                snb.setCode(value.getCode());
                snb.setLabel(value.getLabel());
                snb.setDesc(value.getDesc());
                settingNodeList.add(snb);
            }
            return settingNodeList;
        }
    }

    /**
     * 表格数据删除模式
     */
    @Getter
    public enum TableDataDeleteMode {

        PhysicsDelete("physics_delete",  "物理删除", "物理删除"),

        LogicDelete("logic_delete",  "逻辑删除","逻辑删除,放入回收站");


        private final String code;

        private final String label;

        private final String desc;

        TableDataDeleteMode(String code, String label, String desc) {
            this.code = code;
            this.label = label;
            this.desc = desc;
        }


        public static List<SettingNodeBean> getSettingNodeList() {
            List<SettingNodeBean> settingNodeList = new ArrayList<>();
            for (TableDataDeleteMode value : TableDataDeleteMode.values()) {
                SettingNodeBean snb = new SettingNodeBean();
                snb.setCode(value.getCode());
                snb.setLabel(value.getLabel());
                snb.setDesc(value.getDesc());
                settingNodeList.add(snb);
            }
            return settingNodeList;
        }

    }


    // 是否记录操作日志
    @Getter
    public enum RecordOperLog {

        Record("record", "记录", "记录操作日志"),

        NotRecord("not_record", "不记录", "不记录操作日志")

        ;

        private final String code;

        private final String label;

        private final String desc;

        RecordOperLog(String code, String label, String desc) {
            this.code = code;
            this.label = label;
            this.desc = desc;
        }


        public static List<SettingNodeBean> getSettingNodeList() {
            List<SettingNodeBean> settingNodeList = new ArrayList<>();
            for (RecordOperLog value : RecordOperLog.values()) {
                SettingNodeBean snb = new SettingNodeBean();
                snb.setCode(value.getCode());
                snb.setLabel(value.getLabel());
                snb.setDesc(value.getDesc());
                settingNodeList.add(snb);
            }
            return settingNodeList;
        }

    }





}
